package com.ht.medicaltreatment.activity

import android.view.View
import com.blankj.utilcode.util.FragmentUtils
import com.gym.baselib.base.BaseActivity
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.fragment.LocationFragment
import com.ht.medicaltreatment.fragment.OrderFragment
import kotlinx.android.synthetic.main.activity_asset_inventory_layout.imgBack
import kotlinx.android.synthetic.main.activity_asset_inventory_layout.imgLocation
import kotlinx.android.synthetic.main.activity_asset_inventory_layout.imgOrder
import kotlinx.android.synthetic.main.activity_asset_inventory_layout.tvLocation
import kotlinx.android.synthetic.main.activity_asset_inventory_layout.tvOrder
import kotlinx.android.synthetic.main.view_stub_layout.imgViewStubProgress
import kotlinx.android.synthetic.main.view_stub_layout.tvViewStubProgress
import kotlinx.android.synthetic.main.view_stub_layout.viewStub

/**
 * 资产盘点
 */
class AssetInventoryActivity : BaseActivity(), View.OnClickListener {

    private val orderFragment = OrderFragment()
    private val locationFragment = LocationFragment()

    override fun getLayoutId() = R.layout.view_stub_layout

    override fun init() {
        ////StatusBarCompat.setTranslucent(window, true)

        viewStub.setOnInflateListener { viewStub, view ->
            tvViewStubProgress.visibility = View.GONE
            imgViewStubProgress.visibility = View.GONE
            FragmentUtils.add(supportFragmentManager,orderFragment,R.id.flContent,true)
            FragmentUtils.add(supportFragmentManager,locationFragment,R.id.flContent,false)
            initClick()
        }
        viewStub.postDelayed({
            viewStub.layoutResource = R.layout.activity_asset_inventory_layout
            viewStub.inflate()
        },300)
    }


    private fun initClick() {
        tvOrder.setOnClickListener(this)
        imgOrder.setOnClickListener(this)
        imgLocation.setOnClickListener(this)
        tvLocation.setOnClickListener(this)
        imgBack.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when(v){
            tvOrder,
            imgOrder -> {
                imgOrder.setBackgroundResource(R.drawable.icon_zc_white)
                imgLocation.setBackgroundResource(R.drawable.icon_zc_top_bg)
                FragmentUtils.showHide(orderFragment,locationFragment)
            }

            tvLocation,
            imgLocation -> {
                imgLocation.setBackgroundResource(R.drawable.icon_zc_white)
                imgOrder.setBackgroundResource(R.drawable.icon_zc_top_bg)
                FragmentUtils.showHide(locationFragment,orderFragment)
            }

            imgBack -> finish()
        }
    }

}
